﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using JEdwonTune.Lib.Data;

namespace JEdwonTune.Lib {
    public static class MyUtil {
        public static String TuneBuildVersion {
            get { return "1.1.2011.5.18.1"; }
        }
        public static String CrudVersion {
            get { return "1.0"; }
        }
        public static String VdVersion {
            get { return "1.0"; }
        }
        public static String AuthenticationVersion {
            get { return "1.0"; }
        }
        public static String JskitVirtualDir {
            get { return "jskit.org"; }
        }

        public static String EmptyCrudCfg{
            get {
                return "<?xml version=\"1.0\" encoding=\"utf-8\" ?><jedwon xmlns=\"urn:edwon-cn:configuration\"><crud version=\"" + CrudVersion + "\"><models></models><datasource></datasource></crud></jedwon>";
            }
        }
        public static String EmptyVdCfg {
            get {
                return "<?xml version=\"1.0\" encoding=\"utf-8\" ?><jedwon xmlns=\"urn:edwon-cn:configuration\"><validation version=\"" + VdVersion + "\" /></jedwon>";
            }
        }
        public static String EmptyAuthenticationCfg {
            get {
                return "<?xml version=\"1.0\" encoding=\"utf-8\" ?><jedwon xmlns=\"urn:edwon-cn:configuration\"><authentication version=\"" + AuthenticationVersion + "\" ><roles></roles><operations></operations></authentication></jedwon>";
            }
        }
        public const String OPTION_FILENAME = "options.data";

        public static Boolean ParseBooleanAttr(XmlNode n, String attr, Boolean def) {
            if (n.Attributes[attr]!=null) {
                String val = n.Attributes[attr].Value.ToLower().Trim();
                if (val == "") return def;
                return (val == "yes" || val == "1" || val == "true");
            } else {
                return def;
            }
        }
        public static String ParseName2EOStyle(String oldName) {
            String _newName = "";
            if (oldName.IndexOf("_") != -1) {
                String[] names = oldName.Split('_');
                for (int i = 0; i < names.Length; i++) {
                    if (names[i].Length > 1)
                        _newName += names[i].Substring(0, 1).ToUpper() + names[i].Substring(1).ToLower();
                    else
                        _newName += names[i].ToUpper();
                }
            } else {
                if (oldName.Length > 1)
                    _newName = oldName.Substring(0, 1).ToUpper() + oldName.Substring(1).ToLower();
                else
                    _newName = oldName.ToUpper();
            }
            return _newName;
        }

    }
}
